package com.hxd.otc.module.my.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseActivity;
import com.hxd.otc.common.UserHelper;
import com.hxd.otc.dialog.ShareLinkDialog;
import com.hxd.otc.module.my.contract.ShareThePromotionContract;
import com.hxd.otc.module.my.presenter.ShareThePromotionPresenter;
import com.hxd.otc.utils.AddressUtil;
import com.hxd.otc.utils.UIUtils;
import com.hxd.otc.widget.TitleBar;
import com.scwang.smartrefresh.layout.util.DensityUtil;
import com.uuzuche.lib_zxing.activity.CodeUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by lzy on 2018/12/20 0020.
 * description ${我的推广码}
 */
public class ShareThePromotionActivity extends BaseActivity<ShareThePromotionPresenter> implements ShareThePromotionContract.IView {
    @BindView(R.id.title_bar)
    TitleBar mTitleBar;
    @BindView(R.id.tv_my_promotional_code)
    TextView mTvMyPromotionalCode;
    @BindView(R.id.iv_copy_my_promotional_code)
    ImageView mIvCopyMyPromotionalCode;
    @BindView(R.id.tv_recommended_download_link)
    TextView mTvRecommendedDownloadLink;
    @BindView(R.id.tv_wei_chat_share)
    TextView mTvWeiChatShare;
    @BindView(R.id.tv_recommended_qr_code)
    TextView mTvRecommendedQrCode;
    @BindView(R.id.iv_recommended_qr_code)
    ImageView mIvRecommendedQrCode;
    @BindView(R.id.tv_generate_my_poster)
    TextView mTvGenerateMyPoster;
    private ShareLinkDialog mShareLinkDialog;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_share_the_promotion;
    }

    @Override
    protected ShareThePromotionPresenter createPresenter() {
        return new ShareThePromotionPresenter(this);
    }

    @Override
    protected void initView() {
        mTvMyPromotionalCode.setText(UserHelper.getInviteCode());
        String recommendedAddress = UserHelper.getRecommendedAddress();
        mTvRecommendedDownloadLink.setText(recommendedAddress);
        mIvRecommendedQrCode.setImageBitmap(CodeUtils.createImage(recommendedAddress, DensityUtil.dp2px(120), DensityUtil.dp2px(120), null));
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void initEvent() {
    }

    @OnClick({R.id.iv_copy_my_promotional_code, R.id.tv_recommended_download_link, R.id.tv_wei_chat_share, R.id.tv_recommended_qr_code, R.id.tv_generate_my_poster})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_copy_my_promotional_code:
                AddressUtil.copyAddress(this, mTvMyPromotionalCode.getText().toString(), getString(R.string.copy_promotional_code_success));
                break;
            case R.id.tv_recommended_download_link:
                AddressUtil.copyAddress(this, mTvRecommendedDownloadLink.getText().toString(), getString(R.string.copy_recommended_download_link_success));
                break;
            case R.id.tv_wei_chat_share:
                openShareLinkDialog();
                break;
            case R.id.tv_generate_my_poster:
                $startActivity(DownloadPosterActivity.class);
                break;
        }
    }

    private void openShareLinkDialog() {
        if (mShareLinkDialog == null) {
            mShareLinkDialog = new ShareLinkDialog(this)
                    .setTitle(getString(R.string.your_promotion_link_has_been_generated))
                    .setLink(mTvRecommendedDownloadLink.getText().toString())
                    .setContent("")
                    .isCopyLink(true)
                    .setConfirmText(getString(R.string.lets_go_to_wechat_and_paste_that));
        }
        mShareLinkDialog.show();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        UIUtils.dismissDialog(mShareLinkDialog);
    }
}
